//
//  LoginModel.m
//  MUBATE
//
//  Created by sunbin on 2017/2/15.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "LoginModel.h"

@implementation LoginModel
+ (instancetype)shareInstance
{
    static LoginModel *_instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
}

- (void)loginWithAccount:(NSString *)account password:(NSString *)pwd
                 success:(void (^)(NSDictionary * loginresults, NSString* loginRequestmsg))loginSuccess
                 failure:(void (^)(NSDictionary * loginresults, responseState resMake, NSString* loginRequestError))loginFailed
{

    NSDictionary *params = @{@"store_name":account ,
                             @"pwd":pwd,
                             @"sign":SIGN};
    [ZL_NetworkHelper POST:STORELOGIN parameters:params success:^(id responseObject) {
        NSDictionary *dic  = (NSDictionary *)responseObject;
        NSString *res = IF_NULL_TO_STRING([dic objectForKey:@"res"]);
        NSString *msg = IF_NULL_TO_STRING([dic objectForKey:@"msg"]);
        
        NSDictionary *data = [dic objectForKey:@"data"];

        if ([res isEqualToString:@"1"]) {
            [YConfig saveOwnAccount:account andPassword:pwd];//保存账号与密码

            loginSuccess(data ,msg);
        }else{
            loginFailed(nil , Error ,msg);
        }
    } failure:^(NSError *error) {
        loginFailed(nil , Failure ,error.localizedDescription);

    }];


}





@end
